//
//  AuthStateViewController.m
//  RENTVISITOR
//
//  Created by wonder on 2017/9/1.
//  Copyright © 2017年 UNN. All rights reserved.
//

#import "AuthStateViewController.h"
#import "RentVieitor.h"
#import "SecondViewController.h"
#import "CompanyAuViewController.h"

@interface AuthStateViewController ()

@end

@implementation AuthStateViewController {
    
    UILabel *stateLabel;
    UILabel *hintLabel;
    UIImageView *imgView;
    UIButton *changeBtn;
    UIImageView *imgview;
    UIImageView *imgview2;
}

- (void)viewDidLoad {
    
    [super viewDidLoad];
    
    self.view.backgroundColor = BackgroundColor;
    [self creatLeftView];

    if (self.iscuccess == YES) {
        
        [self reloadSuccData];
    }
    
    if (self.iscuccess == NO) {
        
        [self reloadData];
    }
    
}

- (void)creatLeftView {
    
    UIView *headView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, KWidth, 120)];
    headView.backgroundColor = [Utils colorConvertFromString:@"#1fae0c"];
    [self.view addSubview:headView];
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 20, KWidth-200, 40)];
    label.text = @"经纪人认证";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:17];
    label.textColor = [UIColor whiteColor];
    [headView addSubview:label];
    // 自定义导航栏左侧按钮
    UIButton * leftBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    leftBtn.frame = CGRectMake(15, 20+12, 100,30);
    [leftBtn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 10, 90)];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左-left"] forState:UIControlStateHighlighted];
    [leftBtn setImage:[UIImage imageNamed:@"箭头左-left"] forState:UIControlStateNormal];
    [leftBtn addTarget:self action:@selector(backAction) forControlEvents:UIControlEventTouchUpInside];
    [headView addSubview:leftBtn];
    
    // 自定义导航栏左侧按钮
//    UIButton * rightBtn = [UIButton buttonWithType:UIButtonTypeSystem];
//    rightBtn.frame = CGRectMake(KWidth-65, 20+10, 50, 20);
//    [rightBtn setTitle:@"下一步" forState:UIControlStateNormal];
//    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    [rightBtn addTarget:self action:@selector(nextAction) forControlEvents:UIControlEventTouchUpInside];
//    [headView addSubview:rightBtn];
    
    imgview2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, KWidth, KWidth*90/648)];
    imgview2.image = [UIImage imageNamed:@"third_bd"];
    [headView addSubview:imgview2];
    
    stateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 125/2+120, KWidth, 30)];
    stateLabel.text = @"审核结果,通过审核";
    stateLabel.font = [UIFont systemFontOfSize:17];
    stateLabel.textAlignment = NSTextAlignmentCenter;
    stateLabel.textColor = [Utils colorConvertFromString:@"#1fae0c"];
    [self.view addSubview:stateLabel];
    
    hintLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 125/2+30+120, KWidth, 30)];
    hintLabel.text = @"您的信息已经认证成功";
    hintLabel.userInteractionEnabled = NO;
    hintLabel.textAlignment = NSTextAlignmentCenter;
    hintLabel.font = [UIFont systemFontOfSize:13];
    hintLabel.textColor = [Utils colorConvertFromString:@"#666666"];
    [self.view addSubview:hintLabel];
    //添加手势
    UITapGestureRecognizer * PrivateLetterTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAvatarView)];
    PrivateLetterTap.numberOfTouchesRequired = 1; //手指数
    PrivateLetterTap.numberOfTapsRequired = 1; //tap次数
    [hintLabel addGestureRecognizer:PrivateLetterTap];
    
    imgView = [[UIImageView alloc] initWithFrame:CGRectMake((KWidth-100)/2,  125/2+90+120, 100, 100)];
    imgView.image = [UIImage imageNamed:@"认证成功"];
    [self.view addSubview:imgView];
    
    changeBtn = [UIButton buttonWithType:UIButtonTypeSystem];
    changeBtn.frame = CGRectMake((KWidth-235)/2,360+60, 235, 40);
    changeBtn.enabled = YES;
    [changeBtn setBackgroundColor:[Utils colorConvertFromString:@"#1fae0c"]];
    [changeBtn setTitle:@"立即发布房源" forState:UIControlStateNormal];
    [changeBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    changeBtn.layer.masksToBounds = YES;
    [changeBtn addTarget:self action:@selector(perfectAction) forControlEvents:UIControlEventTouchUpInside];
    changeBtn.layer.cornerRadius = 2;
    [self.view addSubview:changeBtn];

}

- (void)reloadSuccData {
    
    stateLabel.text = @"审核结果,通过审核";
    hintLabel.text = @"您的信息已经认证成功";
    imgView.image = [UIImage imageNamed:@"认证成功"];
    [changeBtn setTitle:@"立即发布房源" forState:UIControlStateNormal];
    imgview2.image = [UIImage imageNamed:@"joinSuccess"];
    
}

- (void)reloadData {
    
    stateLabel.text = @"审核结果,未通过审核";
    hintLabel.text = [NSString stringWithFormat:@"原因:%@",self.reason];
    imgView.image = [UIImage imageNamed:@"未通过认证"];
    [changeBtn setTitle:@"重新提交信息" forState:UIControlStateNormal];
    imgview2.image = [UIImage imageNamed:@"joinDefaut"];
}


- (void)tapAvatarView {
    
    
}

- (void)perfectAction {
    
    if (self.iscuccess == YES) {
        
        [APPDELEGATE showPro:@"跳发布房源界面"];
        return;
    }
    
    if (self.iscuccess == NO) {
        
       
        if ([self.type isEqualToString:@"1"]) {
            
            //个人经纪人认证
            SecondViewController *sendVc = [[SecondViewController alloc] init];
            [self.navigationController pushViewController:sendVc animated:YES];
            return;

        }
        
        if ([self.type isEqualToString:@"2"]) {
            
            //公司经纪人认证
            CompanyAuViewController *companyVc = [[CompanyAuViewController alloc] init];
            [self.navigationController pushViewController:companyVc animated:YES];
            return;
        }
        
           }
}

- (void)backAction {
    
    [self.navigationController popViewControllerAnimated:YES];
}



@end
